package org.iwidget.model.javascript;
import org.iwidget.desktop.model.ElementWindow;
import org.iwidget.desktop.model.WidgetElement;
import org.mozilla.javascript.ScriptableObject;
/**
 *
 * @author Muhammad Hakim A
 */


public class WindowElementJS extends ScriptableObject
{

    public String getClassName()
    {
        if(elementData != null)
            return elementData.getName();
        else
            return "Text";
    }

    public WindowElementJS()
    {
        propertyChange = false;
        elementData = new ElementWindow();
        elementData.setName("Window");
    }

    public WindowElementJS(WidgetElement widget)
    {
        propertyChange = false;
        elementData = new ElementWindow(widget);
        elementData.setName("Window");
    }

    public WindowElementJS(WidgetElement widget, String name)
    {
        propertyChange = false;
        elementData = new ElementWindow(widget);
        elementData.setName(name);
        setDefaults();
    }

    public ElementWindow getElementData()
    {
        return elementData;
    }

    public void setElementData(ElementWindow d)
    {
        elementData = d;
    }

    private void setDefaults()
    {
        try
        {
            defineProperty("height", org.iwidget.model.javascript.WindowElementJS.class, 0);
            defineProperty("name", org.iwidget.model.javascript.WindowElementJS.class, 0);
            defineProperty("opacity", org.iwidget.model.javascript.WindowElementJS.class, 0);
            defineProperty("title", org.iwidget.model.javascript.WindowElementJS.class, 0);
            defineProperty("visible", org.iwidget.model.javascript.WindowElementJS.class, 0);
            defineProperty("width", org.iwidget.model.javascript.WindowElementJS.class, 0);
            defineProperty("x", org.iwidget.model.javascript.WindowElementJS.class, 0);
            defineProperty("y", org.iwidget.model.javascript.WindowElementJS.class, 0);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    public synchronized void jsConstructor()
    {
    }

    public int getHeight()
    {
        return elementData.getHeight();
    }

    public void setHeight(int i)
    {
        elementData.setHeight(i);
        setPropertyChange();
    }

    public String getName()
    {
        return elementData.getName();
    }

    public void setName(String s)
    {
        elementData.setName(s);
    }

    public int getOpacity()
    {
        return elementData.getOpacity();
    }

    public void setOpacity(int i)
    {
        elementData.setOpacity(i);
    }

    public String getTitle()
    {
        return elementData.getTitle();
    }

    public void setTitle(String s)
    {
        elementData.setTitle(s);
    }

    public boolean getVisible()
    {
        return elementData.getVisible();
    }

    public void setVisible(boolean b)
    {
        elementData.setVisible(b);
    }

    public int getWidth()
    {
        return elementData.getWidth();
    }

    public void setWidth(int i)
    {
        elementData.setWidth(i);
        setPropertyChange();
    }

    public int getX()
    {
        return elementData.getX();
    }

    public void setX(int i)
    {
        elementData.setX(i);
        setPropertyChange();
    }

    public int getY()
    {
        return elementData.getY();
    }

    public void setY(int i)
    {
        elementData.setY(i);
        setPropertyChange();
    }

    public void setPropertyChange()
    {
        propertyChange = true;
    }

    public void resetPropertyChange()
    {
        propertyChange = false;
    }

    public boolean hasPropertyChanged()
    {
        return propertyChange;
    }

    private static final long serialVersionUID = 0x2d35343935313630L;
    ElementWindow elementData;
    protected boolean propertyChange;
}